/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uk.ac.cam.can.watermarking;

import uk.ac.cam.can.watermarking.misc.CSVDataSet;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Random;

/**
 *
 * @author Thomas
 */
public class WaterMarking {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception{
        CSVDataSet csv = new CSVDataSet();
        generateRandom("./data/random.txt", 500);
        csv.readFromFile("./data/random.txt", ";");
        Random rand = new Random();
        long key = rand.nextLong();
        Watermark w = new Watermark(csv, Watermark.AKH_ALGORITHM);
        w.mark(key);
        csv.writeToFile("./data/result.txt", ";");
        //w.mark(878777889);
        //w.mark(587668325);
        CSVDataSet csv2 = new CSVDataSet();
        csv2.readFromFile("./data/result.txt", ";");
        csv2.round(10);
        csv2.remove(0.5);
        csv2.writeToFile("./data/result.txt", ";");
        

        CSVDataSet csv3= new CSVDataSet();
        csv3.readFromFile("./data/result.txt", ";");        
        Watermark w2 = new Watermark(csv3, Watermark.AKH_ALGORITHM);
        System.out.println(w2.checkMark(key)+" should be 1.0");
        
    }
    
    private static void generateRandom(String fileName, int max_value) throws Exception{
        BufferedWriter buff = new BufferedWriter(new FileWriter(fileName));
        Random rand = new Random();
        for(int i = 0; i < 1000; i++){
            buff.write(i+";");
            buff.write(rand.nextInt(max_value)+";");
            buff.newLine();
        }
        buff.flush();
        buff.close();
    }
}
